using System;
using UnityEngine;

public class MainFrame : MonoBehaviour
{
    private MainFrameProperty _staticProperties;
    public MainFrameProperty _frameProperties;
    private MainFrameProperty _currentProperties;//todo: do not break the frame
    private BuffManager _buffManager;
    public GameObject _turrent;
    private Weapon _weapon;

    public Action ON_Idle = delegate { };
    public Action ON_Move = delegate { };
    public Action ON_Attack = delegate { };
    public Action ON_Hit = delegate { };
    public Action ON_Death = delegate { };
    public Action ON_PerformSkill = delegate { };

    private void Start()
    {
        _buffManager = GetComponent<BuffManager>();
        _weapon = _turrent.GetComponent<Weapon>();
        _buffManager.ON_PropertyUpdate += UpdateProperty;
    }

    private void Update()
    {
        Fire();
        if (Input.GetKeyDown(KeyCode.G))
        {
            _staticProperties = new MainFrameProperty(AssetsManager.AssetsManagerInstance._cruiser_Dic["testCruiser"]);//todo: cruiser generator
            _frameProperties = _staticProperties;
            _currentProperties = _frameProperties;//initialize with fully health; todo: threshold
        }
    }

    private void UpdateProperty()
    {
        _frameProperties = new MainFrameProperty(_buffManager._sumModifier._baseAddition/*may be negative*/
            + _buffManager._sumModifier._basePercentage/*may be negative*/
            * (_buffManager._sumModifier._baseAdd/*may be negative*/
            + _staticProperties));
        Debug.Log(_frameProperties.MoveSpeed);
    }

    private void Fire()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            _weapon.Fire();
        }
    }

    //private void InputManager()//todo
    //{
    //}
}
